package ui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;

import ui.panel.CustomerSelectionPanel;
import ui.panel.OrderPanel;

/**
 * Action listener for the customer maintenance panel
 * @author Martin Schophaus
 *
 */
public class CustomerSelectionListener implements ActionListener{
	private CustomerSelectionPanel custPan;
	private OrderPanel ordPan;
	private JDialog dialog;
	
	/**
	 * Constructor sets the panels with which the listener works
	 * @param custPan Customer panel
	 * @param ordPan Order panel
	 * @param dialog Dialog
	 */
	public CustomerSelectionListener(CustomerSelectionPanel custPan, OrderPanel ordPan, JDialog dialog){
		this.custPan = custPan;
		this.ordPan = ordPan;
		this.dialog = dialog;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("selectCust")){
			try{
				ordPan.setCustomer(custPan.custList.getSelectedItem());
				dialog.dispose();
			} catch (NullPointerException ex){}
		}
	}
}
